<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/base.jspf"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>代理返点管理</title>
<style type="text/css">
	.p-c-flexwrapper {
	    width: 49%;
		display:inline;
		align-items:center;
		margin-right:16px;
		margin-bottom:32px;
		
	}
	.p-c-flexwrapper > span {
		width:80px;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	.p-c-flexwrapper > .form-control {
		width:150px;
	}
	.input-auto {
		width:auto;
		display: inline;
		margin-bottom: 20px;
	}
	table th,table tr,table td {
	text-align: center;
	vertical-align:middle;
	}
</style>
</head>
<body>
	<div style="display:flex;"><button  class="save btn btn-primary btn-lg" >新增</button></div>
	<table id="table-i-qqAccountList" class="table table-striped table-bordered table-hover" style="margin-top: 20px;">
		<thead>
			<tr>
			<th style="display:none;"></th>
			<th>代理等级</th>
			<th>代理返点率</th>
			<th>返点类型</th>
			<th>操作时间</th>
			<th>操作状态</th>
			<th>操作用户</th>
			<th>返点操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	
	<!-- 新增 -->
 	 	<div class="modal fade" id="addAndEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		        <div class="modal-header" style="height: 10px;">
					<span style="float: left; font-size:13px;margin-top: -10px;">添加返点 </span>
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">&times;</button>
				</div>
		            <div class="modal-body">
		            	<p class="p-c-flexwrapper"><span>代理等级：</span><input id="obj-nick_name" class="form-control input-auto"></p>
		            	<p class="p-c-flexwrapper"><span>代理返点率：</span><input id="obj-name" class="form-control input-auto"></p>
		            	<p class="p-c-flexwrapper" style="display: block;width:100%;"><span>返点类型：</span><select id="obj-admin_type" required class="form-control input-auto">
		            		<option value="1">充值返点</option>
		            		<option value="2">打码返点</option>
		            	</select>
		            	</p>
		            	
		            </div>
		            <div class="modal-footer">
		                <button type="button" class="btn btn-primary" id="button-i-submitSaveKefu">提交</button>
		                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		            </div>
		        </div>
		     </div>
		  </div>
		  
		  <!-- 修改 -->
		   	 	<div class="modal fade" id="updateAndEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		        <div class="modal-header" style="height: 10px;">
					<span style="float: left; font-size:13px;margin-top: -10px;">修改返点 </span>
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">&times;</button>
				</div>
		            <div class="modal-body">
		            	<p class="p-c-flexwrapper"><span>代理等级：</span><input id="obj-nick_name1" class="form-control input-auto" readonly></p>
		            	<p class="p-c-flexwrapper"><span>代理返点率：</span><input id="obj-name1" class="form-control input-auto"></p>
		            	
		            </div>
		            <div class="modal-footer">
		                <button type="button" class="btn btn-primary" id="button-i-submitSaveKefu1">提交</button>
		                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		            </div>
		        </div>
		     </div>
		  </div>
		  
	<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script type="text/javascript">
		 $(".save").on("click", function(e) {
			$("#addAndEditModal").modal("show")
		}) 
		
		$("#table-i-qqAccountList").DataTable({
			  "bLengthChange": true,      
		      "bAutoWidth": false,
		      "bSort": false,
		     
		      'aLengthMenu':[5, 10, 20], 	
		       //"order": [[ 9, "asc" ]],  
		       "searching": true, 
		       "dom": "t<'tableinfo'i<'tableSearch'p>l>",    //让共多少条记录，多少页，每页显示多少条在一排
		       "language": {//语言设置  
		            "lengthMenu": "每页显示 _MENU_ 条记录",     
		            "zeroRecords": "没有检索到数据",     
		            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
		            "info": "没有数据",     
		            "oPaginate": {     
		                "sFirst": "首页",     
		                "sPrevious": "前一页",     
		                "sNext": "后一页",     
		                "sLast": "尾页"    
		          	},
		            "search":"搜索:",
		            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
		            "infoEmpty":      "没有找到匹配的信息",
		         },  
		         
	          "drawCallback": function( settings ) {
	        	 $(".input-c-mySwitch").bootstrapSwitch()
	         }, 
	          "ajax": {
	        	 "type": "POST",
	        	 "url": "/agents/findAgentSetup.do",
	        	 "dataSrc": function(json) {
	        		 var newJson = json.data;
	        		 for (var i = 0; i < newJson.length; i++) {
	         			var item = newJson[i]
	         			 var stateValue = ""
	        			 if (item.state == "1") {
	        				 stateValue = "checked"
	        			 } else {
	        				 stateValue = ""
	        			 }
	         			if(item.rebate_type==1){
	         				item.rebate_type="充值返点"
	         			}else{
	         				item.rebate_type="打码返点"
	         			}
	         			item.agent_grade=item.agent_grade+"级";
         				item.state = "<input class='input-c-mySwitch' data-size='small' type='checkbox' " + stateValue + " data-on-text='启用' data-on-color='success' data-off-color='danger' data-off-text='禁用' />"
	        		 }
	        		 return newJson;
	          	 } 
	         },
	         "columns": [
				 {"data": "id", "className": "hidden-td id-edit-td"},
				 {"data": "agent_grade", "className": "agent_grade-edit-td"},
                 {"data": "rebate_ratio", "className": "rebate_ratio-edit-td"},
                 { "data": "rebate_type","className": "rebate_type-td"},
                 {"data": "created_time", "className": "created_time-edit-td"},
                 {"data": "state", "className": "state-edit-td"},
                 {"data": "operator_name", "className": "operator_name-edit-td"},
                 {"data": null, "defaultContent": "<button class='btn btn-info btn-c-editBankInfo btn-sm'>修改</button>  <button class='btn btn-danger btn-c-delBankInfo btn-sm'>删除</button>"},
             ]
	        
		 })	
		 
		 bindJinYongQiYongSwitch("#table-i-qqAccountList", "/agents/updateAgentSetup.do", "state");
	   			var rebate_type
				 $("#button-i-submitSaveKefu").on("click",function(event){
					 if($(".p-c-flexwrapper input").val()==""){
						alert("请填写完整信息");
					} 
					 if($("#obj-admin_type").val=="充值返点"){
						 rebate_type=1;
					 }else{
						 rebate_type=2; 
					 }
					$("#addAndEditModal").modal("hide")
			 	$.ajax({
					type: "POST",
		       	 	url: "/agents/insertAgentSetup.do",
		       	 	data:{
		       	 		"agent_grade":$("#obj-nick_name").val(),
		       	 		"rebate_ratio":$("#obj-name").val(),
		       	 		"rebate_type":rebate_type,
		       	 		},
		       	 	success:function(data){
		       	 		$("#table-i-qqAccountList").DataTable().ajax.reload();
		   	 			alert("添加成功")
		   	 		},
				}) 
			})
			
			var id;
			$("#table-i-qqAccountList").on("click", ".btn-c-editBankInfo", function(event) {
				$("#updateAndEditModal").modal("show")
				$("#obj-nick_name1").val($(this).parent().siblings(".agent_grade-edit-td").text());
				$("#obj-name1").val($(this).parent().siblings(".rebate_ratio-edit-td").text()),
				id=$(this).parent().siblings(".id-edit-td").text()
			})
		 		
			  $("#updateAndEditModal").on("click", "#button-i-submitSaveKefu1", function(event) {
				 $("#updateAndEditModal").modal("hide")
				$.ajax({
					type: "POST",
		       	 	url: "/agents/updateAgentSetup.do",
		       	 	data:{
		       	 			"agent_grade":$("#obj-nick_name1").val().substring(0,1),
	       	 				"rebate_ratio":$("#obj-name1").val(),
	       	 				"id":id,
		       	 		},
		       	 	success:function(data){
		       	 		$("#table-i-qqAccountList").DataTable().ajax.reload();
		       	 		alert("修改成功")
		       	 	}
				})
			}) 
			
			 $("#table-i-qqAccountList").on("click", ".btn-c-delBankInfo", function(event) {
				$.ajax({
					type: "POST",
		       	 	url: "/agents/deleteAgentSetup.do",
		       	 	data:{
		       	 		"id":$(this).parent().siblings(".id-edit-td").text()
		       	 		},
		       	 	success:function(data){
		       	 	 $("#table-i-qqAccountList").DataTable().ajax.reload();
		       	 	alert("删除成功")
		       	 	}	
				})
			}) 
	
	
	</script>
</body>
</html>